/**
 * <p>Title: HighScore</p>
 * <p>Description: A representation of one hall of fame's position</p>
 * @author Guilherme Mauro Germoglio
 */

import java.io.*;

public class HighScore
    implements Serializable, Comparable {

  // atributes
  private String name;
  private double score;
  private int bulletsHit;
  private int bulletsSpent;
  private final String lineSeparator = System.getProperty("line.separator");
  // methods

  /**
   * The HighScore's constructor.
   * @param name A String with the name of the player
   * @param score His/her score
   * @param bulletsHit The number of bullets that hit any asteroid
   * @param bulletsSpent The amount of bullets spent
   */
  public HighScore(String name, double score, int bulletsHit, int bulletsSpent) {
    this.name = name;
    this.score = score;
    this.bulletsHit = bulletsHit;
    this.bulletsSpent = bulletsSpent;
  }

  /**
   * Returns the player's name
   * @return The player's name
   */
  public String getName() {
    return name;
  }

  /**
   * Returns the player's score
   * @return The player's score
   */

  public double getScore() {
    return score;
  }

  /**
   * Implements the well known compareTo().
   * @param object The object it will be compared with
   * @return Everyone knows what the compareTo() does. I said everyone, do you hear?!
   */
  public int compareTo(Object object) {
    if (! (object instanceof HighScore))
      return 2;
    double otherScore = ( (HighScore) object).getScore();
    double otherAccuracy = ( (HighScore) object).getAccuracy();
    double thisScore = getScore();
    double thisAccuracy = getAccuracy();
    if (thisScore == otherScore)
      if (thisAccuracy == otherAccuracy)
        return 0;
      else if (thisAccuracy < otherAccuracy)
        return -1;
      else
        return 1;
    else
    if (thisScore < otherScore)
      return -1;
    else
      return 1;
  }

  /**
   * Returns the player's accuracy.
   * @return The player's accuracy.
   */
  private double getAccuracy() {
    return ( (double) ( (int) ( ( (double) bulletsHit / (double) bulletsSpent) *
                               10000)) / 100);
  }

  /**
   * Implements the well known toString()
   * @return toString()... No comments
   */
  public String toString() {
    return getName() + lineSeparator + getScore() + lineSeparator +
        "Accuracy: " + getAccuracy() + "%";
  }
}